package cn.iocoder.yudao.module.member.controller.admin.collectNotes;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.SortingField;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.member.controller.admin.collectNotes.vo.*;
import cn.iocoder.yudao.module.member.convert.collectNotes.CollectNotesConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.collectNotes.CollectNotesDO;
import cn.iocoder.yudao.module.member.service.collectNotes.CollectNotesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Api(tags = "管理后台 - 收藏备注")
@RestController
@RequestMapping("/member/collect-notes")
@Validated
public class CollectNotesController {

    @Resource
    private CollectNotesService collectNotesService;


    @PostMapping("/saveCollect")
    @ApiOperation("运营端-收藏/取消收藏")
    @TenantIgnore
    public CommonResult<Long> saveCollect(@Valid @RequestBody CollectNotesCreateReqVO createReqVO) {
        return success(collectNotesService.createCollectNotes(createReqVO));
    }
    @PostMapping("/saveNotes")
    @ApiOperation("运营端-添加备注")
    @TenantIgnore
    public CommonResult<Long> saveNotes(@Valid @RequestBody CollectNotesCreateReqVO createReqVO) {
        if(StringUtils.isBlank(createReqVO.getRemarks())){
            return error("备注信息不能为空");
        }
        return success(collectNotesService.createCollectNotes(createReqVO));
    }


    @PostMapping("/getNotesPage")
    @ApiOperation("运营端-历史备注")
    @TenantIgnore
    public CommonResult<PageResult<CollectNotesRespVO>> getCollectNotesPage(@Valid @RequestBody CollectNotesPageReqVO pageVO) {
        if(  null==pageVO.getSortField()){
            SortingField sf=new SortingField();
            sf.setField("n.update_time");
            sf.setOrder("desc");
            pageVO.setSortField(sf);
        }
        PageResult<CollectNotesRespVO> pageResult = collectNotesService.getCollectNotesPage(pageVO);
        return success(pageResult);
    }
}
